/*
 * Copyright (C) Francisco Morero Peyrona. All rights reserved.
 *
 * This software is published under the terms of Open Source 
 * License version 1.1, a copy of which has been included with this
 * distribution in the License.txt file.  
 */

package jdbcmanager.swing.table;

import java.util.*;



/**
 * This table shows pairs of values of type: Property / Value.
 * <p>
 * The perfect example is to show <code>System.getProperties()</code> pairs.
 *  
 * @author Francisco Morero Peyrona
 */

public class JxTableMap extends JxTableVector
{
   public JxTableMap()
   {
      this( new String[] { "Property", "Value" } );
   }
   
   public JxTableMap( String[] asHead )
   {
      setHead( asHead );
   }
   
   /**
    * 
    * @param asHead
    */
   public void setHead( String[] asHead )
   {
      Vector vTmp = new Vector();
      
      for( int n = 0; n < asHead.length; n++ )
         vTmp.add( asHead[n] );
         
      super.setHead( vTmp );
   }
   
   /**
    * Add a set of rows at one time.
    * 
    * @param map Rows to add.
    */
   public void setData( Map map )
   {
      Vector vTable = new Vector( map.size() );
      
      for( Iterator it = map.keySet().iterator(); it.hasNext(); )
      {
         Object oKey = it.next();
         Vector vRow = new Vector( 2 );
                vRow.add( oKey );
                vRow.add( map.get( oKey ) );
                
         vTable.add( vRow );
      }
      
      super.setData( vTable );
   }
   
   /**
    * Add one single row to existing data.
    * 
    * @param oProperty
    * @param oValue
    */
   public void addRow( Object oProperty, Object oValue )
   {
      Vector vRow = new Vector();
             vRow.add( oProperty );
             vRow.add( oValue );
          
      super.addRow( vRow );
   }
}
